
TOPDIR := $(shell pwd)
PACKSHOPROOT := $(TOP_DIR)


PACKSHOP_USER=$(USER)
PACKSHOP_DATE:=$(shell date '+%Y%m%d%H%M%S')

PRODUCT_NAME := TIE

ifndef PRODUCT_NAME
PRODUCT_NAME:=$(shell basename $(shell pwd))
endif

PACKSHOP_TOOLS:=$(PACKSHOPROOT)/tools

PACKSHOP_BUILD := $(shell pwd)/dist

ifeq ($(PACKSHOP_BUILD), )
PACKSHOP_WORK=/home/share/$(PACKSHOP_USER)/Tmp/$(PRODUCT_NAME)/$(PACKSHOP_DATE)
else
PACKSHOP_WORK=$(PACKSHOP_BUILD)/$(OEM_VENDOR)/$(SPECIAL_ID)/$(PACKSHOP_DATE)
endif


PACKSHOP_PRODUCT_NAME=$(PRODUCT_NAME).$(PACKSHOP_DATE)\($(VER_TYPE)\)#

ifeq ($(RELEASE), 1)
INTERMEDIATEDIR=$(PACKSHOP_WORK)/INTERMEDIATEDIR
else
INTERMEDIATEDIR=$(TOP_DIR)/bin/demo/$(PRODUCT_NAME)/$(GUI_VENDOR)/$(OEM_VENDOR)/$(SPECIAL_ID)/intermediate
endif

TARGETDIR = $(INTERMEDIATEDIR)/bin

UPF_NAME=$(PACKSHOP_WORK)/modules/$(PACKSHOP_PRODUCT_NAME).upf
	
# ������ϵ��Ŀ��
#preBuild: ����֮ǰ��, ��Ҫ׼������������
#Build: �������
#postBuild ׼���ù���Ŀ¼֮�����֮����
#Install ���
pack: preBuild Build postBuild
	#@mkdir -p $(INTERMEDIATEDIR)
	#@cp $(PACKSHOP_WORK)/modules $(INTERMEDIATEDIR)/ -rf
	#@echo lastest dir modules : $(INTERMEDIATEDIR)/modules

buildDir:
ifeq ($(VER_TYPE),)
	@echo useage: make pack VER_TYPE=[inner alpha beta rc]
	exit 1
endif
	
	@echo "����������Ŀ¼:$(PACKSHOP_WORK)"
	@if [ ! -d $(PACKSHOP_WORK) ]; \
		then mkdir $(PACKSHOP_WORK) -p; \
	fi
		
	@echo "modules����Ŀ¼:$(PACKSHOP_WORK)/modules"
	@if [ ! -d $(PACKSHOP_WORK)/modules ]; \
		then mkdir $(PACKSHOP_WORK)/modules; \
	fi
	rm $(PACKSHOP_WORK)/modules/* -rf
		
	@echo "Packshop����Ŀ¼:$(PACKSHOP_WORK)/Packshop"
	@if [ ! -d $(PACKSHOP_WORK)/Packshop ]; \
		then mkdir $(PACKSHOP_WORK)/Packshop; \
	fi
	
	@echo "algmodel:$(PACKSHOP_WORK)/algmodel"
	@if [ ! -d $(PACKSHOP_WORK)/algmodel ]; \
		then mkdir $(PACKSHOP_WORK)/algmodel; \
	fi
	
custom_pre:
	rm -fr $(PACKSHOP_WORK)/algmodel/*
	echo "create Custom img to modules"
	
	#�����Զ�������
	$(shell pwd)/tools/cpscript cpd $(shell pwd)/algmodel $(PACKSHOP_WORK)/algmodel
	
custom_img:
	@echo "Start to make custom.squashfs ..."
	$(shell pwd)/tools/make_ext4fs -l 256M -s  $(PACKSHOP_WORK)/modules/algmodel.ext4 $(PACKSHOP_WORK)/algmodel
	@if [ $$? -ne 0 ]; then								\
		echo "make $(PACKSHOP_WORK)/modules/custom.algmodel fail!";	\
		exit 1;											\
	fi

preBuild: buildDir custom_pre

Build:custom_img

postBuild:	
	cp -f $(shell pwd)/setup $(PACKSHOP_WORK)/modules/
	@rm $(UPF_NAME) -f
		
	echo creat upf
	$(shell pwd)/tools/zip -j $(UPF_NAME) \
					$(PACKSHOP_WORK)/modules/algmodel.ext4 \
					$(PACKSHOP_WORK)/modules/setup
	
	@echo "################################"
	@echo Build complete
	@echo PACKSHOPROOT: $(PACKSHOPROOT)
	@echo PACKSHOP_WORK: $(PACKSHOP_WORK)
	@echo "################################"
	@mv $(UPF_NAME) $(shell pwd)/dist/
	@rm -rf $(PACKSHOP_WORK)

clean:
	make -f $(SRCROOT)/Build/$(PRODUCT_NAME)/Makefile INTERMEDIATEDIR=$(INTERMEDIATEDIR) clean

distclean:
	make -f $(SRCROOT)/Build/$(PRODUCT_NAME)/Makefile INTERMEDIATEDIR=$(INTERMEDIATEDIR) clean
	rm	$(PACKSHOP_WORK) -rf;
	